<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1"><title id="dp20941">EXECUTE</title><body><p id="sql_command_desc">Runs a prepared SQL statement.</p><section id="section2"><title>Synopsis</title><codeblock id="sql_command_synopsis">EXECUTE <varname>name</varname> [ (<varname>parameter</varname> [, ...] ) ]</codeblock></section><section id="section3"><title>Description</title><p><codeph>EXECUTE</codeph> is used to run a previously prepared statement.
Since prepared statements only exist for the duration of a session, the
prepared statement must have been created by a <codeph>PREPARE</codeph>
statement run earlier in the current session. </p><p>If the <codeph>PREPARE</codeph> statement that created the statement
specified some parameters, a compatible set of parameters must be passed
to the <codeph>EXECUTE</codeph> statement, or else an error is raised.
Note that (unlike functions) prepared statements are not overloaded based
on the type or number of their parameters; the name of a prepared statement
must be unique within a database session.</p><p>For more information on the creation and usage of prepared statements,
see <codeph>PREPARE</codeph>.</p></section><section id="section4"><title>Parameters</title><parml><plentry><pt><varname>name</varname></pt><pd>The name of the prepared statement to run. </pd></plentry><plentry><pt><varname>parameter</varname></pt><pd>The actual value of a parameter to the prepared statement. This must
be an expression yielding a value that is compatible with the data type
of this parameter, as was determined when the prepared statement was
created.</pd></plentry></parml></section><section id="section5"><title>Examples</title><p>Create a prepared statement for an <codeph>INSERT</codeph> statement,
and then run it:</p><codeblock>PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO 
foo VALUES($1, $2, $3, $4);
EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);</codeblock></section><section id="section6"><title>Compatibility</title><p>The SQL standard includes an <codeph>EXECUTE</codeph> statement, but
it is only for use in embedded SQL. This version of the <codeph>EXECUTE</codeph>
statement also uses a somewhat different syntax. </p></section><section id="section7"><title>See Also</title><p><codeph><xref href="DEALLOCATE.xml#topic1" type="topic" format="dita"/></codeph>, <codeph><xref
            href="./PREPARE.xml#topic1" type="topic" format="dita"/></codeph></p></section></body></topic>
